program dgleHoD;

uses
  Windows,
  SysUtils,
  DGLE in '..\DGLEngine\DGLE.pas',
  DGLE_Types in '..\DGLEngine\DGLE_Types.pas',
  DGLE_Base in '..\DGLEngine\DGLE_Base.pas',
  DGLE_CoreRenderer in '..\DGLEngine\DGLE_CoreRenderer.pas',
  Engine in 'Engine.pas',
  Scene in 'Scene.pas',
  SceneMainMenu in 'SceneMainMenu.pas',
  SceneManager in 'SceneManager.pas',
  SceneEngine in 'SceneEngine.pas',
  uBox in 'uBox.pas',
  uBeaRlibZip in '..\BeaRlibZip\uBeaRlibZip.pas',
  Button in 'Button.pas',
  SceneAbout in 'SceneAbout.pas',
  SceneOptions in 'SceneOptions.pas',
  SceneCustom in 'SceneCustom.pas',
  SceneGame in 'SceneGame.pas',
  Tile in 'Tile.pas',
  Creature in 'Creature.pas',
  Item in 'Item.pas',
  Digit in 'Digit.pas',
  Entity in 'Entity.pas',
  Bar in 'Bar.pas',
  IntBar in 'IntBar.pas',
  IntUseBar in 'IntUseBar.pas',
  MapCustom in 'MapCustom.pas',
  Map in 'Map.pas',
  uPF in 'uPF.pas';

procedure Init(pParametr: Pointer); stdcall;
begin
  Engine.Init;
end;

procedure Update(pParametr: Pointer); stdcall;
begin
  Engine.Update;
end;

procedure Render(pParametr: Pointer); stdcall;
begin
  Engine.Render;
 end;

procedure Free(pParametr: Pointer); stdcall;
begin
  Engine.Free;
end;

begin
  Randomize;
  {$IF COMPILERVERSION >= 18}   
  ReportMemoryLeaksOnShutdown := True;
  {$IFEND}
  if(GetEngine(DLL_PATH, pEngineCore)) then
  begin


    // Test
    pEngineCore.GetDesktopResolution(SCREEN_WIDTH, SCREEN_HEIGHT);
    Dec(SCREEN_WIDTH, 500); Dec(SCREEN_HEIGHT, 300);

    GAME_SCR_WIDTH := SCREEN_WIDTH div TILE_SIZE;
    GAME_SCR_HEIGHT := SCREEN_HEIGHT div TILE_SIZE;

    if not odd(GAME_SCR_WIDTH) then Dec(GAME_SCR_WIDTH);
    SCR_LEFT := (SCREEN_WIDTH - ((GAME_SCR_WIDTH) * TILE_SIZE)) div 2;
    if not odd(GAME_SCR_HEIGHT) then Dec(GAME_SCR_HEIGHT);
    SCR_TOP := (SCREEN_HEIGHT - ((GAME_SCR_HEIGHT) * TILE_SIZE)) div 2;


    if(SUCCEEDED(pEngineCore.InitializeEngine(0, APP_CAPT, EngineWindow(SCREEN_WIDTH, SCREEN_HEIGHT,
      false, false, MM_NONE, EWF_ALLOW_SIZEING)))) then
    begin
      //pEngineCore.ConsoleVisible(True);
      pEngineCore.AddProcedure(EPT_INIT,   @Init);
      pEngineCore.AddProcedure(EPT_UPDATE, @Update);
      pEngineCore.AddProcedure(EPT_RENDER, @Render);
      pEngineCore.AddProcedure(EPT_FREE,   @Free);
      pEngineCore.AddEventListener(ET_ON_FULLSCREEN, @OnFullScreenEvent, nil);
      pEngineCore.StartEngine();
    end;
    FreeEngine();
  end else MessageBox(0, 'Couldnt load ' + DLL_PATH + '!', APP_CAPT, MB_OK or MB_ICONERROR or MB_SETFOREGROUND);
end.
